<!-- 无集群 -->
<#if response.notOK>
<div class="main">
	<form class="form-inline" role="form">
		<div class="form-group">
			<label for="mqClusterSelect"> 集群: 暂无数据 </label>
		</div>
	</form>
	<hr/>
</div>
<#else>
<style type="text/css">
	li#previous.disabled a {color:#CCC}
	li#next.disabled a {color:#CCC}
	pre {
		font-size: 11px;
		line-height: 1;
		padding: 0;
		margin: 0;
		border: 0;
		background-color: transparent;
	}
	.fixedHeight {
		max-height: 400px;
		overflow-y: auto;
	}
	#theadTable tr td{
		border: 0px;
	}
</style>
<!--tree插件 -->
<link href="${request.contextPath}/resources/treetable/jquery.treetable.css" rel="stylesheet">
<link href="${request.contextPath}/resources/treetable/jquery.treetable.theme.default.css" rel="stylesheet">
<script src="${request.contextPath}/resources/treetable/jquery.treetable.js"></script>
<!-- 有集群 -->
<div class="main">
	<form class="form-inline" role="form">
		<div class="form-group">
			<label for="mqClusterSelect"> 集群: </label>
			<select name="type" id="mqClusterSelect" class="form-control select2_category">
				<#list response.result.mqCluster as mqCluster>
					<option value="${mqCluster.id}"
						<#if mqCluster.id == response.result.selectedMQCluster.id>selected="selected"</#if>
					>${mqCluster.name}</option>
				</#list>
			</select>
		</div>
		<#if response.result.hasNameServer>
			<div class="form-group">
				<button type="button" class="btn btn-success" onclick="addBroker()" data-target="#addBrokerModal" data-toggle="modal"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;Master</button>
				<button type="button" class="btn btn-success" title="添加broker节点后，从Name Server抓取broker列表，刷入数据库中，用于broker列表展示及监控" onclick="refresh()" data-toggle="modal"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>&nbsp;broker</button>
			</div>
		</#if>
		<#if response.result.brokerGroup??>
			<div class="form-group" style="float:right;">
				<button type="button" data-placement="bottom" title="该功能用于将已有RocketMQ集群的topic写入topic表中（可以执行多次，因为数据库有唯一索引）。" class="btn btn-success" onclick="initTopic()" data-toggle="modal">topic初始化</button>
				<button type="button" data-placement="bottom" title="该功能用于将已有RocketMQ集群的topic的在线消费者写入consumer表中（可以执行多次，因为数据库有唯一索引）。" class="btn btn-success" onclick="initConsumer()" data-toggle="modal">consumer初始化</button>
			</div>
		</#if>
		<div class="form-group" style="float:right;margin-right:3px;">
			<button title="将broker数据迁移至远程机器" type="button" class="btn btn-success"  onclick="migrateBrokerData()" data-target="#migrateBrokerDataModal" data-toggle="modal">数据迁移</button>
		</div>
	</form>
	<hr/>
	<table class="table table-striped table-hover" style="margin-top: 0px">
		<thead>
			<tr>
				<td>Broker名字</td>
				<td>BrokerID</td>
				<td>地址</td>
				<td>生产量/秒</td>
				<td>消费量/秒</td>
				<td>延时消息量</td>
				<td data-toggle="tooltip" title="slave的commitlog落后于master多少">落后量</td>
				<td>版本</td>
				<td data-toggle="tooltip" title="MQCloud会定时监控broker是否存活">状态</td>
				<td>监控时间</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
			<#if response.result.brokerGroup??>
			<#assign brokerGroup=response.result.brokerGroup />
			<#assign i = 0>
			<#list brokerGroup?keys as key>
				<#list brokerGroup[key]?keys as bkey>
					<tr>
						<#assign i = i + 1>
						<#if bkey == "0">
							<#if sohu>
								<td rowspan=${brokerGroup[key]?size}><a onclick="showBrokerStoreStatModal('${brokerGroup[key][bkey].brokerAddr}')" data-toggle="tooltip" title="查看master存储性能" href="#">${key}</a></td>
							<#else>
								<td rowspan=${brokerGroup[key]?size}>${key}</td>
							</#if>
						</#if>
						<td>
							<#if bkey == "0">
								<a href='#' onclick="setIp('${brokerGroup[key][bkey].brokerAddr}')" data-target="#brokerTrafficModal" data-toggle="modal" title="查看master流量">${bkey}</a>
							<#else>
								${bkey}
							</#if>
						</td>
						<td><a href="#" onclick="showBrokerConfigModal('${brokerGroup[key][bkey].brokerAddr}')" data-toggle="tooltip" title="线上配置">${brokerGroup[key][bkey].brokerAddr}</a></td>
						<td>
							<#if brokerGroup[key][bkey].inTps??>${brokerGroup[key][bkey].inTps}</#if>	
						</td>
						<td>
							<#if brokerGroup[key][bkey].outTps??>${brokerGroup[key][bkey].outTps}</#if>	
						</td>
						<#if bkey == "0">
							<td>
							<#if brokerGroup[key][bkey].delayQueue??>
								<a href="#" data-target="#delayMessageOffsetModal${i}" data-toggle="modal" title="查看延迟队列数据">
								${brokerGroup[key][bkey].delayQueue.delayMessageOffset}
							<#else>
								0
							</#if>
							<#if brokerGroup[key][bkey].delayQueue??>
								</a>
								<div id="delayMessageOffsetModal${i}" class="modal fade" tabindex="-1" data-width="400" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal"
													aria-hidden="true">&times;</button>
												<h4 class="modal-title">${brokerGroup[key][bkey].brokerAddr}延迟队列数据</h4>
											</div>
											<table class="table table-striped table-hover" style="margin-top: 0px">
												<thead>
													<tr>
														<td>延时级别</td>
														<td>当前偏移量</td>
														<td>最大偏移量</td>
														<td>消息量</td>
													</tr>
												</thead>
												<tbody>
													<#list brokerGroup[key][bkey].delayQueue.delayQueueOffsetList as offset>
														<tr>
															<td>${offset.messageDelayLevel.time}</td>
															<td>
																${offset.curOffset}
															</td>
															<td>
																${offset.maxOffset}
															</td>
															<td>
																<#assign minus = offset.maxOffset - offset.curOffset>
																<#if minus gt 0><a href="#" onclick="showDelayMessageModal('${offset.messageDelayLevel.time}', ${offset.curOffset}, ${offset.maxOffset}, '${key}', ${offset.messageDelayLevel.level-1})" data-toggle="tooltip" title="查看消息"></#if>
																${minus}
																<#if minus gt 0></a></#if>
															</td>
														<tr>
													</#list>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</#if>
							</td>
							<td>0</td>
						<#else>
							<td data-toggle="tooltip" title="由于slave不会处理延时队列的消息，故一直为0">0</td>
							<#assign fallbehindSize=brokerGroup[key]["0"].commitLogMaxOffset - brokerGroup[key][bkey].commitLogMaxOffset />
							<td data-toggle="tooltip" title="${fallbehindSize}">${brokerGroup[key]["0"].format(fallbehindSize)}</td>
						</#if>
						<td>
							<#if brokerGroup[key][bkey].version??>${brokerGroup[key][bkey].version}</#if>
						</td>
						<td>
							<#if brokerGroup[key][bkey].checkStatus == 2>
								<font style='font-weight:bold' color='red'>${brokerGroup[key][bkey].checkStatusDesc}</font>
							<#else>
								${brokerGroup[key][bkey].checkStatusDesc}
							</#if>
						</td>
						<td>
							<#if brokerGroup[key][bkey].checkTime??>${brokerGroup[key][bkey].checkTime}</#if>
						</td>
						<td>
							<#if brokerGroup[key][bkey].info??>
								<button data-target="#clusterInfoModal${i}" data-toggle="modal" type="button" class="btn btn-sm btn-success"
								title="查看当前broker的其他状态信息"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></button>
								<div id="clusterInfoModal${i}" class="modal fade" tabindex="-1" data-width="400" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal"
													aria-hidden="true">&times;</button>
												<h4 class="modal-title">其余信息展示</h4>
											</div>
											<table class="table table-striped table-hover" style="margin-top: 0px">
												<thead>
													<tr>
														<td>指标项</td>
														<td>值</td>
													</tr>
												</thead>
												<tbody>
													<#list brokerGroup[key][bkey].info?keys as ikey>
														<tr>
															<td>${ikey}</td>
															<td>
																${brokerGroup[key][bkey].info[ikey]}
															</td>
														<tr>
													</#list>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</#if>
							<#if brokerGroup[key][bkey].version??>
							<#if bkey == "0">
								<button title="禁止客户端写入，broker下线前需要先禁止写入，等没有人写入后，再下线" type="button" onclick="program('${brokerGroup[key][bkey].brokerAddr}', 'program${i}')" class="btn btn-sm btn-success" data-target="#nowriteModal${i}" data-toggle="modal">停写</button>
								<button title="已经停写的broker，可以进行关闭操作" type="button" class="btn btn-sm btn-success" data-target="#brokerOfflineModal${i}" onclick="program('${brokerGroup[key][bkey].brokerAddr}', 'brokerOfflineProgram${i}')" data-toggle="modal">下线</button>
								<#if brokerGroup[key]?size <= 1>
									<button title="增加slave" type="button" class="btn btn-sm btn-success"  onclick="addBroker('${key}')" data-target="#addBrokerModal" data-toggle="modal"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;Slave</button>
								</#if>
								<!-- 停写 -->
								<div id="nowriteModal${i}" class="modal fade" tabindex="-1" data-width="400">
									<div class="modal-dialog" style="width:1000px">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h4 class="modal-title">确定要停止写入?</h4>
											</div>
											<form class="form-horizontal form-bordered form-row-stripped" id="nowrite${i}">
												<div class="modal-body">
													<div class="row">
														<div class="col-md-12">
															<div class="form-body">
																<div class="form-group">
																	<label class="control-label col-md-1"> broker: </label>
															        <div class="col-md-4">
																		<input type="text" name="broker" value="${key}" class="form-control" readonly />
																	</div>
																</div>
																<div class="form-group">
																	<label class="control-label col-md-1"> 进程: </label>
															        <div class="col-md-10">
																		<textarea id="program${i}" type="text" name="info" rows="10" class="form-control" readonly></textarea>
																	</div>
																</div>
																<input type="hidden" name="cid" value="${response.result.selectedMQCluster.id}">
															</div>
														</div>
													</div>
												</div>
												<div class="modal-footer">
													<button type="button" data-dismiss="modal" class="btn" >取消</button>
													<button type="button" class="btn btn-primary" onclick="nowrite('nowrite${i}')" id="nowrite${i}Btn">确定</button>
												</div>
											</form>
										</div>
									</div>
								</div>
							<#else>
								<button title="slave可以直接进行关闭" type="button" class="btn btn-sm btn-success" data-target="#brokerOfflineModal${i}" onclick="program('${brokerGroup[key][bkey].brokerAddr}', 'brokerOfflineProgram${i}')" data-toggle="modal">下线</button>
							</#if>
							<#else>
								<button title="启动broker" data-toggle="tooltip" type="button" id="${key}<#if bkey != "0">-s</#if>Btn" class="btn btn-sm btn-success" onclick="startupBroker('${brokerGroup[key][bkey].brokerAddr}', '${key}<#if bkey != "0">-s</#if>')">启动</button>
								<button title="在当前机器更新broker并保留数据" type="button" class="btn btn-sm btn-success"  onclick="upgradeBroker('${brokerGroup[key][bkey].brokerAddr}', '${key}<#if bkey != "0">-s</#if>')" data-target="#upgradeBrokerModal" data-toggle="modal">升级</button>
								<button title="将当前机器broker数据迁移至远程机器" type="button" class="btn btn-sm btn-success"  onclick="migrateBrokerData('${brokerGroup[key][bkey].brokerAddr}', '${key}<#if bkey != "0">-s</#if>')" data-target="#migrateBrokerDataModal" data-toggle="modal">数据迁移</button>
							</#if>
							
							<!-- 下线 -->
							<div id="brokerOfflineModal${i}" class="modal fade" tabindex="-1" data-width="400">
								<div class="modal-dialog" style="width:1000px">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title">确定要下线broker?</h4>
										</div>
										<form class="form-horizontal form-bordered form-row-stripped" id="brokerOffline${i}">
											<div class="modal-body">
												<div class="row">
													<div class="col-md-12">
														<div class="form-body">
															<div class="form-group">
																<label class="control-label col-md-1"> 地址: </label>
														        <div class="col-md-4">
																	<input type="text" name="addr" value="${brokerGroup[key][bkey].brokerAddr}" class="form-control" readonly />
																</div>
															</div>
															<div class="form-group">
																<label class="control-label col-md-1"> 进程: </label>
														        <div class="col-md-10">
																	<textarea id="brokerOfflineProgram${i}" type="text" rows="10" class="form-control" readonly></textarea>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
											<div class="modal-footer">
												<button type="button" data-dismiss="modal" class="btn" >取消</button>
												<button type="button" class="btn btn-primary" onclick="brokerOffline('brokerOffline${i}')" id="brokerOffline${i}Btn">确定</button>
											</div>
										</form>
									</div>
								</div>
							</div>
						</td>
					</tr>
				</#list>
			</#list>
			<#else>
				<tr>
					<td colspan=11 class="text-center">暂无数据</td>
				</tr>
			</#if>
		</tbody>
	</table>
	
	<!-- 	准备搜索部分 -->
	<hr>
	<div class="col-md-12">
		<div style="float:left;margin:10px 5px;"><h5><b>${response.result.selectedMQCluster.name}</b> 流量图</h5></div>
		<div id="cluster_search" style="float:right;margin:10px 0px;"></div>
	</div>
	<!-- 	准备曲线图 -->
	<div id="cluster_lineChart"><center>暂无数据</center></div>
</div>

<!-- 新建broker -->
<div id="addBrokerModal" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="width:1000px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">新建Broker</h4><b style="font-size:9px;"><i>请建好/opt/mqcloud目录并将其赋权给${username}用户：chown ${username}:${username} /opt/mqcloud</i></b>
			</div>
			<div class="modal-body">
				<div class="row bs-wizard" style="border-bottom:0;">
	                <div id="brokerServer" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">服务器选择</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">broker安装到哪</div>
	                </div>
	                
	                <div id="brokerJdk" class="col-xs-2 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">JDK校验</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">校验jdk是否配置完成，版本要求>=1.8</div>
	                </div>
	                
	                <div id="brokerPort" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">端口校验</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">检查端口是否被占用</div>
	                </div>
	                
	                <div id="brokerDir" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">目录校验</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">检查安装目录是否被占用</div>
	                </div>
	                
	                <div id="brokerScp" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">下载安装包</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">从仓库下载安装包到服务器/tmp下</div>
	                </div>
	                <div id="brokerUnzip" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">解压</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">解压到安装目录下</div>
	                </div>
	                <div id="brokerConfig" class="col-xs-2 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">生成配置文件</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">生成mq.conf,run.sh和topic配置</div>
	                </div>
	                <div id="brokerInitConfig" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">初始化配置</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">执行os.sh</div>
	                </div>
	                <div id="brokerStartup" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">启动</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">启动broker</div>
	                </div>
	                <div id="brokerProgram" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">完成</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">获取启动后的进程信息</div>
	                </div>
	            </div>
				<form class="form-horizontal form-bordered form-row-stripped" id="broker">
					<div class="form-body">
						<div class="form-group">
							<label class="control-label col-md-3"> 服务器: </label>
					        <div class="col-md-8">
								<select id="brokerServerSelect" class="selectpicker" title="请选择" data-live-search-placeholder="搜索" name="ip" data-live-search="true"></select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 所属集群: </label>
					        <div class="col-md-8">
								<input type="text" value="${response.result.selectedMQCluster.name}" class="form-control" readonly/>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 进程: </label>
					        <div class="col-md-8">
								<textarea id="brokerProgramInfo" type="text" rows="1" class="form-control" readonly></textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 提示: </label>
					        <div class="col-md-8">
								<div class="form-control-static">如果安装遇到错误警告，请登录服务器解决后再<b>继续</b>执行</div>
							</div>
						</div>
					</div>
					<input type="hidden" id="dir" name="dir" value=""/>
					<table class="table table-striped table-hover" style="margin-top: 0px;word-break:break-all; word-wrap:break-all;">
						<colgroup>
							<col width="100px">
							<col width="250px">
							<col width="200px">
							<col width="100px">
							<col>
							<col width='46px'>
							<col width='60px'>
						</colgroup>
						<thead>
							<tr>
								<td>分组</td>
								<td>key</td>
								<td>线上值</td>
								<td>默认值</td>
								<td>描述</td>
								<td data-toggle="tooltip" title="修改后需要重启则表示不支持动态修改，反之则支持">动改</td>
							</tr>
						</thead>
						<tbody id="clusterConfigBody">
						</tbody>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" id="installBtn" data-toggle="modal" onclick="install('broker')"><span id="brokerInstall">一键安装<span></button>
			</div>
		</div>
	</div>
</div>

<!-- 升级部署broker -->
<div id="upgradeBrokerModal" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="width:1000px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">升级Broker</h4><b style="font-size:9px;"><i>请提前在通用配置里rocketmqFilePath配置项, 配置好待升级的安装包地址。如需修改broker配置,请在升级完毕后进行修改。</i></b>
			</div>
			<div class="modal-body">
				<div class="row bs-wizard" style="border-bottom:0;">
					<div id="upgradeBrokerBackup" class="col-xs-1 bs-wizard-step disabled">
						<div class="text-center bs-wizard-stepnum">备份数据</div>
						<div class="progress"><div class="progress-bar"></div></div>
						<a href="#" class="bs-wizard-dot"></a>
						<div class="bs-wizard-info text-center">备份原安装目录</div>
					</div>

					<div id="upgradeBrokerScp" class="col-xs-2 bs-wizard-step disabled">
						<div class="text-center bs-wizard-stepnum">下载安装包</div>
						<div class="progress"><div class="progress-bar"></div></div>
						<a href="#" class="bs-wizard-dot"></a>
						<div class="bs-wizard-info text-center">从仓库下载最新安装包到服务器/tmp下</div>
					</div>

					<div id="upgradeBrokerUnzip" class="col-xs-2 bs-wizard-step disabled">
						<div class="text-center bs-wizard-stepnum">解压</div>
						<div class="progress"><div class="progress-bar"></div></div>
						<a href="#" class="bs-wizard-dot"></a>
						<div class="bs-wizard-info text-center">解压到安装目录下</div>
					</div>

					<div id="upgradeBrokerRecover" class="col-xs-2 bs-wizard-step disabled">
						<div class="text-center bs-wizard-stepnum">恢复数据</div>
						<div class="progress"><div class="progress-bar"></div></div>
						<a href="#" class="bs-wizard-dot"></a>
						<div class="bs-wizard-info text-center">移动备份数据和配置文件至新的安装目录</div>
					</div>

					<div id="upgradeBrokerStartup" class="col-xs-3 bs-wizard-step disabled">
						<div class="text-center bs-wizard-stepnum">启动</div>
						<div class="progress"><div class="progress-bar"></div></div>
						<a href="#" class="bs-wizard-dot"></a>
						<div class="bs-wizard-info text-center">启动broker</div>
					</div>
					<div id="upgradeBrokerProgram" class="col-xs-2 bs-wizard-step disabled">
						<div class="text-center bs-wizard-stepnum">完成</div>
						<div class="progress"><div class="progress-bar"></div></div>
						<a href="#" class="bs-wizard-dot"></a>
						<div class="bs-wizard-info text-center">获取启动后的进程信息</div>
					</div>
				</div>
				<form class="form-horizontal form-bordered form-row-stripped" id="upgradeBroker">
					<div class="form-body">
						<div class="form-group">
							<label class="control-label col-md-3"> 机器: </label>
							<div class="col-md-8">
								<input type="text" id="upgradeBrokerAddr" name="ipAddr" class="form-control" readonly/>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> brokerName: </label>
							<div class="col-md-8">
								<input type="text" id="upgradeBrokerName" name="dir" class="form-control" readonly/>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 所属集群: </label>
							<div class="col-md-8">
								<input type="text" value="${response.result.selectedMQCluster.name}" class="form-control" readonly/>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 进程: </label>
							<div class="col-md-8">
								<textarea id="upgradeBrokerProgramInfo" type="text" rows="1" class="form-control" readonly></textarea>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3"> 提示: </label>
							<div class="col-md-8">
								<div class="form-control-static">如果升级过程遇到错误警告，请登录服务器解决后再<b>继续</b>执行</div>
							</div>
						</div>
					</div>
					<input type="hidden" id="upgradeBrokerIp" name="ip" value=""/>
					<input type="hidden" id="upgradeBrokerListenPort" name="listenPort" value=""/>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" id="upgradeBtn" data-toggle="modal" onclick="upgrade('upgradeBroker')"><span id="upgradeBrokerKey">一键升级<span></button>
			</div>
		</div>
	</div>
</div>

<!-- 迁移broker数据 -->
<div id="migrateBrokerDataModal" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false">
	<div class="modal-dialog" style="width:1000px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" style="display:inline-block">迁移Broker数据</h4> <b style="font-size:9px;"><i>1.源broker请停写；2.目标broker部署好，但请勿启动。</i></b>
			</div>
			<div class="modal-body">
				<div class="bs-wizard" style="border-bottom:0;margin-right: -15px;">
	                <div id="migrateServer" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">服务器选择</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">选择目标服务器</div>
	                </div>
	                
	                <div id="migrateCheckDir" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">目录校验</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">确保目标目录存在</div>
	                </div>
	                
	                <div id="migrateCreateStorePath" class="col-xs-2 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">创建存储目录</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">在目标机器创建数据存储目录</div>
	                </div>
	                
	                <div id="migrateAuth" class="col-xs-1 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">机器互信</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">源机器与目标机器互信</div>
	                </div>
	                
	                <div id="migrateData" class="col-xs-2 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">源broker数据</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">获取源broker存储数据</div>
	                </div>
	                
	                <div id="migrateScp" class="col-xs-2 bs-wizard-step disabled">
	                  <div class="text-center bs-wizard-stepnum">数据传输</div>
	                  <div class="progress"><div class="progress-bar"></div></div>
	                  <a href="#" class="bs-wizard-dot"></a>
	                  <div class="bs-wizard-info text-center">将源broker存储数据传输至目标broker</div>
	                </div>
	                
					<div id="migrateProgressDiv" class="col-xs-2 progress disabled" style="left:-69px;z-index:1;margin:38px 0;height:15px;padding:0px;">
					    <div class="progress-bar progress-bar-striped" role="progressbar" id="migrateProcessBar" style="background-color: #dcc98c">
					      <span style="line-height:15px;"><b id="migrateSpeed">--</b>&nbsp;&nbsp;&nbsp;<b id="migrated">--</b>/<b id="migrateTotal">--</b></span>
					    </div>
				  	</div>
				  	<div id="migrateFinish" class="col-xs-1 bs-wizard-step disabled" style="left:-96px;">
				  		<div class="text-center bs-wizard-stepnum">完成</div>
	                  	<a href="#" class="bs-wizard-dot"></a>
	                </div>
	            </div>
	            <hr style="clear:both;">
	            <h4>一：配置目标机器及目录</h4>
				<form id="migrateForm" class="form-inline form-bordered form-row-stripped">
					<div class="form-body">
						<div class="form-group">
							<label class="control-label"> 源机器: </label>
							<div>
								<select id="sourceIp" class="selectpicker" title="请选择" data-live-search-placeholder="搜索" name="sourceIp" data-live-search="true"></select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label"> 源broker安装目录: </label>
							<div>
								<input type="text" id="sourceHome" name="sourceHome" class="form-control"/>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label"> 目标机器: </label>
							<div>
								<select id="destIp" class="selectpicker" title="请选择" data-live-search-placeholder="搜索" name="destIp" data-live-search="true"></select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label"> 目标broker安装目录: </label>
							<div>
								<input type="text" id="destHome" name="destHome" class="form-control"/>
							</div>
						</div>
					</div>
				</form>
				<hr>
				<h4>二：迁移数据文件</h4>
				<table id="theadTable" class="treetable" style="margin-bottom: 0px;">
					<colgroup>
						<col>
						<col width="50px">
						<col width="70px">
						<col width="67px">
						<col width="65px">
						<col width="17px">
					</colgroup>
			        <thead>
			          <tr>
			            <td>数据文件</td>
			            <td data-toggle="tooltip" title="文件夹大小为其下文件大小之和">大小</td>
			            <td data-toggle="tooltip" title="标识文件是否传输成功">传输状态</td>
			            <td data-toggle="tooltip" title="标识源文件和目标文件md5是否一致">md5校验</td>
			            <td data-toggle="tooltip" title="标识源文件和目标文件大小是否一致，若md5一致则不校验大小">大小校验</td>
			            <td></td>
			          </tr>
			        </thead>
			    </table>
				<div id="migrateDiv" class="fixedHeight">
				<table id="migrateTable" class="table table-striped table-hover treetable" style="margin-top: 0px">
					<colgroup>
						<col>
						<col width="50px">
						<col width="70px">
						<col width="67px">
						<col width="65px">
					</colgroup>
			        <tbody>
			          <tr>
			          	<td colspan=5 class="text-center">暂无数据</td>
			          </tr>
			        </tbody>
				</table>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" id="migrateBtn" data-toggle="modal" onclick="migrate()">一键迁移</button>
			</div>
		</div>
	</div>
</div>

<!-- broker统计 -->
<div id="brokerTrafficModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog" style="width:1100px;">
		<div class="modal-content">
			<div class="modal-body" style="padding-top:5px;">
				<div id="brokerTrafficChart"></div>
			</div>
		</div>
	</div>
</div>

<!-- 初始化结果 -->
<div id="initModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog" style="width:1000px">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title"><span id="initDiv">topic</span>初始化结果</h4>
			</div>
			<div class="modal-body" id="initBody">
			</div>
		</div>
	</div>
</div>

<!-- 消息查询 -->
<div id="delayMessageModal" class="modal fade" tabindex="-1" aria-hidden="true">
	<div class="modal-dialog" style="width:1000px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">延迟<span id="delayLevel"></span>队列消息查询</h4>
			</div>
			<div style="float:right;margin:10px 0px;">
			<form class="form-inline" id="msgSearchForm">
				<div>
					<!-- 偏移量查询 -->
					<div class="form-group offset">
						<label for="offsetStart"> 起始偏移量: </label>
						<input id="offsetStart" name="offsetStart" type="text" class="form-control" style="width:120px;">
					</div>
					<div class="form-group offset">
			  			<label for="offsetEnd"> 结束偏移量: </label>
						<input id="offsetEnd" name="offsetEnd" type="text" class="form-control" style="width:120px;">
					</div>
					<input type="hidden" id="append" name="append" value="false">
					<input type="hidden" id="toBrokerName" name="toBrokerName">
					<input type="hidden" id="toQueue" name="toQueue">
					<input type="hidden" id="messageParam" name="messageParam" value="${messageQueryCondition.serialize()}">
					<!-- 偏移量查询 -->
					<button type="button" onclick="searchOffsetMessage(false)" class="btn btn-search offset"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
				</div>
			</form>
			</div>
			<table id="dataTable" class="table table-striped table-hover" style="margin-top: 0px;word-break:break-all; word-wrap:break-all;">
				<colgroup>
					<col width="50px">
					<col width="200px">
					<col width="130px">
					<col width="185px">
					<col width="100px">
					<col>
					<col width="120px">
				</colgroup>
				<thead>
					<tr>
						<td>序号</td>
						<td>topic</td>
						<td>客户端</td>
						<td>发送时间</td>
						<td>broker:队列</td>
						<td>消息</td>
						<td id="keysTD">keys</td>
					</tr>
				</thead>
				<tbody>
					<tr class="no_more_data"><td colspan=8 class="text-center">暂无数据</td></tr>
				</tbody>
			</table>
			<ul class="pager" id="pager" style="display:none;">
				<li id="previous" class="previous" onclick="previous()"><a href="javascript:void(0)">&larr; 上一页</a></li>
				<li><a class="pager_tip" href="#">第<b id="pageNum"></b>页，命中数：<b id="sizeNum"></b>，检索数：<b id="searchNum"></b>，预估剩余数：<b id="leftNum"></b></a></li>
				<li id="next" class="next" onclick="next()"><a href="javascript:void(0)">下一页 &rarr;</a></li>
			</ul>
		</div>
	</div>
</div>

<!-- broker性能状态 -->
<div id="brokerStoreStatModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog" style="width:1100px;">
		<div class="modal-content">
			<div class="modal-body" style="padding-top:5px;">
				<!-- 	准备搜索部分 -->
				<div class="row">
					<div class="col-md-12">
						<div style="float:left;margin:10px 5px;"><h5><b id="ipBroker"></b>存储性能统计</h5></div>
						<div id="broker_store_search" style="float:right;margin:10px 0px;"></div>
					</div>
				</div>
				<!-- 	准备曲线图 -->
				<div id="broker_store_lineChart"><center>暂无数据</center></div>
			</div>
		</div>
	</div>
</div>

<!-- broker配置 -->
<div id="brokerConfigModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog" style="width:1100px;">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title"><span id="brokerAddr"></span>线上配置</h4>
			</div>
			<table id="brokerConfigTable" class="table table-striped table-hover" style="margin-top: 0px;word-break:break-all; word-wrap:break-all;">
				<colgroup>
					<col width="100px">
					<col width="280px">
					<col width="250px">
					<col>
					<col width='46px'>
				</colgroup>
				<thead>
					<tr>
						<td>分组</td>
						<td>key</td>
						<td>线上值</td>
						<td>描述</td>
						<td data-toggle="tooltip" title="修改后需要重启则表示不支持动态修改，反之则支持">动改</td>
					</tr>
				</thead>
				<tbody id="brokerConfigBody">
					<tr class="no_more_data"><td colspan=7 class="text-center">暂无数据</td></tr>
				</tbody>
			</table>
			<div class="modal-footer">
				<button type="button" data-dismiss="modal" class="btn" >取消</button>
				<button type="submit" class="btn btn-primary" onclick="modifyBrokerConfig()" data-toggle="tooltip" title="注意：此更新仅对当前broker有效！" id="modifyBrokerConfigBtn">更新</button>
			</div>
		</div>
	</div>
</div>

<script>
var installId = "";
var upgradeId = "";
var method = "";
/**
 * 安装broker
 */
function install(id){
	installId = id;
	if(!$('#'+id+'ServerSelect').val()){
		alert("请先选择服务器");
		return;
	}
	if("broker" == id){
		if(!$('#brokerName').val()){
			alert("请填写brokerName");
			return;
		}
		if(!$('input[name="brokerRole"]').is(":checked")){
			alert("请选择broker角色");
			return;
		}
		if($('#listenPort').length > 0 && !$('#listenPort').val()){
			alert("请填写监听端口");
			return;
		}
		if($('input[name="flushDiskType"]').length > 0 && !$('input[name="flushDiskType"]').is(":checked")){
			alert("请选择刷盘方式");
			return;
		}
		if($('#fileReservedTime').length > 0 && !$('#fileReservedTime').val()){
			alert("请填写数据保留时间");
			return;
		}
	}
	if($('#'+id+'Install').html() == "继续"){
		setTimeout(method+'()', 500);
	} else {
		validateJDK();
	}
	disableBtn("installBtn");
}

/**
 * 升级broker
 */
function upgrade(id) {
	upgradeId = id;
	if($('#'+id+'Key').html() == "继续"){
		setTimeout(method+'()', 500);
	} else {
		upgradeBackup();
	}
	disableBtn("upgradeBtn");
}

/**
 * 升级broker,第一步: 备份数据
 */
function upgradeBackup(){
	var wizardId = upgradeId+"Backup";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/backup',
			$("#"+upgradeId).serialize(),
			function(data){
				if(data.status == 200){
					complete(wizardId);
					// 下载安装包
					setTimeout('upgradeScp()', 1000);
				} else {
					toastr.error("备份数据出错！"+data.message);
					warn(wizardId);
					upgradeGoOn("upgradeBackup");
				}
			}, 'json');
}

/**
 * 升级broker,第二步: 下载安装包
 */
function upgradeScp(){
	var wizardId = upgradeId+"Scp";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/scp',
			$("#"+upgradeId).serialize(),
			function(data){
				if(data.status == 200){
					complete(wizardId);
					// 解压文件
					setTimeout('upgradeUnzip()', 1000);
				} else {
					toastr.error("下载失败！"+data.message);
					warn(wizardId);
					upgradeGoOn("upgradeScp");
				}
			}, 'json');
}
/**
 * 升级broker,第三步: 解压最新安装包到安装目录下
 */
function upgradeUnzip(){
	var wizardId = upgradeId+"Unzip";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/unzip',
			$("#"+upgradeId).serialize(),
			function(data){
				if(data.status == 200){
					complete(wizardId);
					// 恢复数据
					setTimeout('upgradeRecover()', 1000);
				} else {
					toastr.error("解压失败！"+data.message);
					warn(wizardId);
					upgradeGoOn("upgradeUnzip");
				}
			}, 'json');
}

/**
 * 升级broker,第四步: 恢复数据
 */
function upgradeRecover(){
	var wizardId = upgradeId+"Recover";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/recover',
			$("#"+upgradeId).serialize(),
			function(data){
				if(data.status == 200){
					complete(wizardId);
					if(confirm("升级成功，是否直接启动？")){
						// 启动broker
						upgradeStartup();
					} else {
						upgradeGoOn("upgradeStartup");
					}
				} else {
					toastr.error("恢复数据出错！"+data.message);
					warn(wizardId);
					upgradeGoOn("upgradeRecover");
				}
			}, 'json');
}

/**
 * 升级broker,第五步: 启动实例
 */
function upgradeStartup(){
	var wizardId = upgradeId+"Startup";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/startup',
			$("#"+upgradeId).serialize(),
			function(data){
				if(data.status == 200){
					complete(wizardId);
					// 检测进程
					setTimeout('upgradeCheckProgram()', 10000);
				} else {
					toastr.error("启动失败！"+data.message);
					warn(wizardId);
					upgradeGoOn("upgradeStartup");
				}
			}, 'json');
}
/**
 * 升级broker,第六步: 检测启动的进程
 */
function upgradeCheckProgram(){
	var wizardId = upgradeId+"Program";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/check/program',
			$("#"+upgradeId).serialize(),
			function(data){
				if(data.status == 200){
					$("#"+upgradeId+"ProgramInfo").attr("rows", 5).html(data.result);
					complete(wizardId);
					alert("恭喜，升级完成啦！请及时刷新页面");
				} else {
					toastr.error("检查启动进程失败！"+data.message);
					warn(wizardId);
					upgradeGoOn("upgradeCheckProgram");
				}
			}, 'json');
}

/**
 * 继续
 */
function goOn(m){
	$("#"+installId+"Install").html("继续");
	enableBtn("installBtn");
	method = m;
}

/**
 * broker升级,继续
 */
function upgradeGoOn(m){
	$("#"+upgradeId+"Key").html("继续");
	enableBtn("upgradeBtn");
	method = m;
}

/**
 * 校验jdk
 */
function validateJDK(){
	var wizardId = installId+"Jdk";
	active(wizardId);
	$.get('${request.contextPath}/admin/deploy/check/jdk',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	var version = data.result.substring(0, 3);
            	if(version >= 1.8){
            		complete(wizardId);
            		// 校验端口
            		setTimeout('checkPort()', 1000);
            	} else {
            		alert("jdk环境校验失败，最低为1.8，目前版本为："+data.result);
            		warn(wizardId);
            		goOn("validateJDK");
            	}
		    }else{
		    	toastr.error("数据获取失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("validateJDK");
		    }
       }, 'json');
}
/**
 * 端口校验
 */
function checkPort(){
	var wizardId = installId+"Port";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/check/port',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	// 校验目录
            	setTimeout('checkDir()', 1000);
		    } else if(data.status == 500){
		    	toastr.error("端口被该程序占用："+data.result);  
		    	warn(wizardId);
		    	goOn("checkPort");
		    } else {
		    	toastr.error("校验失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("checkPort");
		    }
       }, 'json');
}

/**
 * 目录校验
 */
function checkDir(){
	var wizardId = installId+"Dir";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/check/dir',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	// 下载文件
        		setTimeout('scp()', 1000);
		    } else {
		    	toastr.error("校验失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("checkDir");
		    }
       }, 'json');
}
/**
 * scp
 */
function scp(){
	var wizardId = installId+"Scp";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/scp',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	// 解压文件
        		setTimeout('unzip()', 1000);
		    } else {
		    	toastr.error("下载失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("scp");
		    }
       }, 'json');
}
/**
 * 解压
 */
function unzip(){
	var wizardId = installId+"Unzip";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/unzip',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	// 配置
        		setTimeout('config()', 1000);
		    } else {
		    	toastr.error("解压失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("unzip");
		    }
       }, 'json');
}
/**
 * 配置
 */
function config(){
	var wizardId = installId+"Config";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/config/' + installId,
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	if("ns" == installId){
	            	// 启动
	        		setTimeout('startup()', 1000);
            	}else{
            		// 初始化配置
            		setTimeout('initConfig()', 1000);
            	}
            		
		    } else {
		    	toastr.error("配置失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("config");
		    }
       }, 'json');
}
/**
 * 初始化配置
 */
function initConfig(){
	var wizardId = "brokerInitConfig";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/config/init',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	if(confirm("配置成功，是否直接启动？")){
            		startup();
            	} else {
        			goOn("startup");
            	}
		    } else {
		    	toastr.error("初始化配置失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("initConfig");
		    }
       }, 'json');
}
/**
 * 启动实例
 */
function startup(){
	var wizardId = installId+"Startup";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/startup',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	complete(wizardId);
            	var time = 5000;
            	if("broker" == installId){
            		time = 10000;
            	}
            	// 检测进程
        		setTimeout('checkProgram()', time);
		    } else {
		    	toastr.error("启动失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("startup");
		    }
       }, 'json');
}
/**
 * 检测启动的进程
 */
function checkProgram(){
	var wizardId = installId+"Program";
	active(wizardId);
	$.post('${request.contextPath}/admin/deploy/check/program',
		$("#"+installId).serialize(),
        function(data){
            if(data.status == 200){
            	$("#"+installId+"ProgramInfo").attr("rows", 5).html(data.result);
            	complete(wizardId);
            	alert("恭喜你，安装完成啦！");
            	$("#"+installId+"Install").parent().attr("disabled", "disabled");
		    } else {
		    	toastr.error("检查失败！"+data.message);  
		    	warn(wizardId);
		    	goOn("checkProgram");
		    }
       }, 'json');
}
function addBroker(brokerName){
	$.get('${request.contextPath}/admin/broker/cluster/config',{
			cid: ${response.result.selectedMQCluster.id}
			}, function(data){
	            $("#clusterConfigBody").html(data);
	            $("#brokerClusterName").val('${response.result.selectedMQCluster.name}').attr("readonly","readonly");
	    		$("#brokerIP1").attr("readonly","readonly");
	    		$("#brokerIP2").attr("readonly","readonly");
	    		if(!$("#storePathRootDir").val() && !$("#storePathCommitLog").val()){
		    		$("#brokerName").bind('input propertychange', function(){
		    			$("#dir").val($("#brokerName").val());
		    			$("#storePathRootDir").val("/opt/mqcloud/"+$("#brokerName").val()+"/data");
		    			$("#storePathCommitLog").val("/opt/mqcloud/"+$("#brokerName").val()+"/data/commitlog");
		    		});
	    		}else{
					$("#brokerName").bind('input propertychange', function(){
						$("#dir").val($("#brokerName").val());
					});
				}
	    		if(!$("#rmqAddressServerDomain").val()){
		    		$("#rmqAddressServerDomain").val('${mqcloudDomain}').attr("readonly","readonly");
	    		}
	    		if(!$("#rmqAddressServerSubGroup").val()){
		    		$("#rmqAddressServerSubGroup").val('nsaddr-${response.result.selectedMQCluster.id}').attr("readonly","readonly");
	    		}
	    		if(brokerName){
	    			$("#brokerName").val(brokerName);
	    			$("#dir").val(brokerName+"-s");
	    			if(!$("#storePathRootDir").val()){
		    			$("#storePathRootDir").val("/opt/mqcloud/"+brokerName+"-s/data");
		    		}
	    			if(!$("#storePathCommitLog").val()){
		    			$("#storePathCommitLog").val("/opt/mqcloud/"+brokerName+"-s/data/commitlog");
		    		}
	    			$("#brokerId").val(1);
	    			$('input[name="brokerRole"]').each(function(){
	    				if($(this).val() == 'ASYNC_MASTER' || $(this).val() == 'SYNC_MASTER'){
	    					$(this).next().remove();
	    					$(this).remove();
	    				} else {
	    					$(this).attr("checked", "checked");
	    				}
	    			});
	    		} else {
	    			$("#brokerId").attr("readonly","readonly");
	    			$('input[name="brokerRole"]').each(function(){
	    				if($(this).val() == 'SLAVE'){
	    					$(this).next().remove();
	    					$(this).remove();
	    				}
	    			});
	    		}
	            $('[data-tooltip="true"]').tooltip({
		            container: 'body'
		        });
    		}
	);
	initServerList("brokerServerSelect");
}

function upgradeBroker(brokerAddr, brokerName) {
    $("#upgradeBrokerAddr").val(brokerAddr);
	$("#upgradeBrokerName").val(brokerName);
	$("#upgradeBrokerIp").val(brokerAddr.split(":")[0]);
	$("#upgradeBrokerListenPort").val(brokerAddr.split(":")[1]);
}

function migrateBrokerData(brokerAddr, brokerName) {
	if(brokerAddr){
		var ip = brokerAddr.split(":")[0];		  
		$("#sourceIp").html('<option selected="selected" value="'+ ip +'">'+ ip +'</option>');
		$('#sourceIp').selectpicker('refresh');
		$("#sourceHome").val(brokerName).attr("readonly", "readonly");
	} else {
		initServerList("sourceIp");
	}
	initServerList("destIp");
}

/**
 * 初始化server下拉列表
 */
function initServerList(componentId){
	$.get('${request.contextPath}/admin/server/all',
	        function(data){
	            if(data.status == 200){
	            	var content = "";
	            	for(var i in data.result){
	            		var server = data.result[i];
	            		content += "<option value='"+server.ip+"'>"+server.ip+"</option>";
	            	}
	        		$("#"+componentId).html(content);
	        		$("#"+componentId).selectpicker('refresh');
			    }else{
			    	toastr.error("数据获取失败！"+data.message);  
			    }
        }, 'json');
}
/**
 * 停写
 */
function nowrite(formId){
	disable(formId+"Btn");
	$.post('${request.contextPath}/admin/cluster/nowrite',
			$("#"+formId).serialize(),
	        function(data){
	            if(data.status == 200){
	            	toastr.success("停写成功，请耐心等待客户端写入结束！");  
	            	modalHide(3000, function(){
	            		enable(formId+"Btn");
	            	});
			    }else{
			    	toastr.error("操作失败！"+data.message);  
			    	enable(formId+"Btn");
			    }
        }, 'json');
}

/**
 * 获取进程信息
 */
function program(addr, programId){
	$.get('${request.contextPath}/admin/deploy/program',
			{
				addr: addr
			},
	        function(data){
				$("#"+programId).html(data.result);
        }, 'json');
}

/**
 * 下线
 */
function brokerOffline(formId){
	disable(formId+"Btn");
	$.post('${request.contextPath}/admin/deploy/shutdown',
			$("#"+formId).serialize(),
	        function(data){
	            if(data.status == 200){
	            	toastr.success("下线成功");  
	            	reload(3000);
			    }else{
			    	toastr.error("操作失败！"+data.message);  
			    	enable(formId+"Btn");
			    }
        }, 'json');
}
$('#mqClusterSelect').on('change',function(){
	window.location.href = "${request.contextPath}/admin/cluster/list?cid="+$(this).val();
});

$(function(){
	// broker server select change
	$('#brokerServerSelect').on('shown.bs.select', function(e) {
		active("brokerServer");
		
	});
	$('#brokerServerSelect').on('hidden.bs.select', function(e) {
		if(!$('#brokerServerSelect').val()){
			disableStep("brokerServer");
		} else {
			complete("brokerServer");
		}
	});
	$('#brokerServerSelect').on('changed.bs.select', function(e) {
		$("#brokerIP1").val($(this).val());
		$("#brokerIP2").val($(this).val());
	});
	
	// fix bootstrap model & highcharts resize
	$('#brokerTrafficModal').on('shown.bs.modal', function() {
		brokerTraffic();
	});
	
	// cluster traffic
	lineChart("cluster", function (){
		$("#clusterId").val("${response.result.selectedMQCluster.id}");
	});
	
	<#if RequestParameters.ip?? && RequestParameters.ip != "">
		setIp("${RequestParameters.ip}");
		$('#brokerTrafficModal').modal('show');
	</#if>
	
	// fix bootstrap model & highcharts resize
	$('#brokerStoreStatModal').on('shown.bs.modal', function() {
		lineChart("broker_store", function (){
			$("#brokerIp").val(brokerIp);
		});
	});
	
	<#if RequestParameters.brokerStoreIp?? && RequestParameters.brokerStoreIp != "">
		showBrokerStoreStatModal('${RequestParameters.brokerStoreIp}');
	</#if>
	
	// migrate server select change
	$('#destIp').on('shown.bs.select', function(e) {
		active("migrateServer");
	});
	$('#destIp').on('hidden.bs.select', function(e) {
		if(!$('#destIp').val()){
			disableStep("migrateServer");
		} else {
			complete("migrateServer");
		}
	});
});

function warn(id){
	$("#"+id).addClass("warn");
}
function disableStep(id){
	$("#"+id).removeClass("active").addClass("disabled");
}
function active(id){
	$("#"+id).removeClass("disabled").removeClass("warn").addClass("active");
}
function complete(id){
	$("#"+id).removeClass("active").removeClass("warn").addClass("complete");
}
function disableBtn(id){
	$("#"+id).attr("disabled", "disabled");
}
function enableBtn(id){
	$("#"+id).removeAttr("disabled");
}

var brokerIp;
function setIp(ip){
	brokerIp = ip;
	$("#brokerTrafficChart").empty();
}

/**
 * 获取broker流量图
 */
function brokerTraffic(){
	$.get('${request.contextPath}/admin/cluster/traffic',
		{
		ip: brokerIp
		},
        function(data){
            $("#brokerTrafficChart").html(data);
    });	
}

/**
 * 初始化topic
 */
function initTopic(){
	$("#initBody").empty();
	$("#initDiv").html("topic");
	post('${request.contextPath}/admin/cluster/init/topic',
		{
		cid: ${response.result.selectedMQCluster.id}
		},
        function(data){
			$("#initBody").html(data);
			$('#initModal').modal('show');
    });	
}

/**
 * 初始化consumer
 */
function initConsumer(){
	$("#initBody").empty();
	$("#initDiv").html("consumer");
	post('${request.contextPath}/admin/cluster/init/consumer',
		{
		cid: ${response.result.selectedMQCluster.id}
		},
        function(data){
			$("#initBody").html(data);
			$('#initModal').modal('show');
    });	
}
// 与nameserver同步 broker
function refresh(){
	post('${request.contextPath}/admin/broker/refresh',
		{
			cid: ${response.result.selectedMQCluster.id}
		},
        function(data){
            if(data.status == 200){
				toastr.success("抓取成功，将自动刷新");  
				reload(3000);
		    }else{
		    	toastr.error("抓取失败！"+data.message);
		    }
        }, 'json');
}

// 延时消息搜索
var pageNum = 0;
//显示分页
function showPage(num){
	pageNum = num;
	var comp = $("#data_"+num);
	var size = comp.attr("data_size");
	var search = comp.attr("data_search");
	var left = comp.attr("data_left");
	$("#pageNum").html(num);
	$("#sizeNum").html(size);
	$("#searchNum").html(search);
	$("#leftNum").html(left);
	$("#pager").show();
	if(num == 1){
		$("#previous").addClass("disabled");
	} else {
		$("#previous").removeClass("disabled");
	}
	if(left > 0){
		$("#next").removeClass("disabled");
	} else {
		$("#next").addClass("disabled");
	}
	// 展示数据
	$("#page_"+pageNum).show().siblings("tbody").hide();
}
//上一页
function previous(){
	if(!$("#previous").hasClass("disabled")){
		showPage(pageNum - 1);
	}
}
//下一页
function next(){
	if(!$("#next").hasClass("disabled")){
		if($("#data_"+(pageNum+1)).length > 0){
			showPage(pageNum+1);
		} else {
			searchOffsetMessage(true);
		}
	}
}

function showDelayMessageModal(delay, curOffset, maxOffset, toBrokerName, toQueue){
	$("#offsetStart").val(curOffset);
	$("#offsetEnd").val(maxOffset);
	$("#toBrokerName").val(toBrokerName);
	$("#toQueue").val(toQueue);
	$("#delayLevel").html(delay);
	$("#dataTable tbody").remove();
	$("#dataTable input").remove();
	searchOffsetMessage(false);
	$("#delayMessageModal").modal('show');
}

//偏移量消息搜索
function searchOffsetMessage(append){
	$("#append").val(append);
	post('${request.contextPath}/topic/message/delay/offset/search', $("#msgSearchForm").serialize(), function(data){
		if(!append){
			$("#dataTable tbody").remove();
			$("#dataTable input").remove();
		}
       	$("#dataTable").append(data);
    });
}

function showBrokerStoreStatModal(ip){
	$("#ipBroker").html(ip);
	setIp(ip);
	$("#brokerStoreStatModal").modal('show');
}

function showBrokerConfigModal(addr){
	$("#brokerAddr").html(addr);
	$.get('${request.contextPath}/admin/broker/online/config',
		{
		cid: ${response.result.selectedMQCluster.id},
	    addr:  addr
		},
        function(data){
			$("#brokerConfigBody").html(data);
			$('[data-tooltip="true"]').tooltip({
	            container: 'body'
	        });
			$("#brokerConfigModal").modal('show');
    });	
}

function modifyBrokerConfig(){
	var tip = "";
	var needReboot = false;
	var configParam = "";
	$("#brokerConfigBody input:text").each(function(){
		var nowValue = $.trim($(this).val());
		var prevValue = $(this).attr("data");
		if(nowValue != prevValue){
			if($(this).attr("dynamic") == "false"){
				needReboot = true;
			}
			tip += $(this).attr("name") + "修改为" + nowValue + "\n";
			configParam += $(this).attr("name") + ":" + nowValue + ";";
		}
	})
	$("#brokerConfigBody input:radio:checked").each(function(){
		var nowValue = $.trim($(this).val());
		var prevValue = $(this).attr("data");
		if(nowValue != prevValue){
			if($(this).attr("dynamic") == "false"){
				needReboot = true;
			}
			tip += $(this).attr("name") + "修改为" + nowValue + "\n";
			configParam += $(this).attr("name") + ":" + nowValue + ";";
		}
	})
	if(tip){
		if(needReboot){
			tip += "由于修改了不支持动态修改的项，请更新后重启broker";
		}
		if(confirm(tip)){
			disable("modifyBrokerConfigBtn");
			$.get('${request.contextPath}/admin/broker/update/online/config',
					{
					cid: ${response.result.selectedMQCluster.id},
				    addr:  $("#brokerAddr").html(),
				    config: configParam
					},
			        function(data){
						if(data.status == 200){
			            	toastr.success("操作成功！即将刷新页面！");  	            	
			            	reload(2000);            	
					    }else{
					    	toastr.error("操作失败！"+data.message);  
					    	enable("modifyBrokerConfigBtn");
					    }
			    });	
		}
	} else {
		alert("没有改动，无需更新");
	}
}
/**
 * 启动实例
 */
function startupBroker(ipAddr, dir){
	disable(dir+"Btn");
	$.post('${request.contextPath}/admin/deploy/startup/broker',{
		ipAddr: ipAddr,
		dir: dir
		},function(data){
            if(data.status == 200){
            	toastr.success("启动成功！即将刷新页面！");  	            	
            	reload(5000);   
		    } else {
		    	toastr.error("启动失败！"+data.message);  
		    	enable(dir+"Btn");
		    }
       }, 'json');
}

/**
 * 迁移broker数据
 */
function migrate(){
	if(!$('#sourceIp').val()){
		alert("请选择源服务器");
		return;
	}
	if(!$('#sourceHome').val()){
		alert("请填写源broker安装目录");
		return;
	}
	if(!$('#destIp').val()){
		alert("请选择目标服务器");
		return;
	}
	if($('#destIp').val() == $("#sourceIp").val()){
		alert("源服务器不能与目标服务器相同");
		return;
	}
	if(!$('#destHome').val()){
		alert("请填写目标broker安装目录");
		return;
	}
	if($('#migrateBtn').html() == "继续"){
		setTimeout(method+'()', 500);
	} else {
		checkDestDir();
	}
	disableBtn("migrateBtn");
}

/**
 * 继续
 */
function migrateGoOn(m){
	$("#migrateBtn").html("继续");
	enableBtn("migrateBtn");
	method = m;
}
/**
 * 数据迁移第一步：目录校验
 */
function checkDestDir(){
	active("migrateCheckDir");
	$.post('${request.contextPath}/admin/deploy/check/dir/exist',
		$("#migrateForm").serialize(),
        function(data){
            if(data.status == 200){
            	complete("migrateCheckDir");
        		setTimeout('createStorePath()', 500);
		    } else {
		    	toastr.error("校验失败！"+data.message);  
		    	migrateGoOn("checkDestDir");
		    	warn("migrateCheckDir");
		    }
       }, 'json');
}
/**
 * 数据迁移第二步：在目标机器创建数据存储目录
 */
function createStorePath(){
	active("migrateCreateStorePath");
	$.post('${request.contextPath}/admin/deploy/create/store/path',
		$("#migrateForm").serialize(),
        function(data){
            if(data.status == 200){
            	complete("migrateCreateStorePath");
        		setTimeout('authentication()', 500);
		    } else {
		    	toastr.error("创建失败！"+data.message);  
		    	migrateGoOn("createStorePath");
		    	warn("migrateCreateStorePath");
		    }
       }, 'json');
}
/**
 * 数据迁移第三步：机器互信
 */
function authentication(){
	active("migrateAuth");
	$.post('${request.contextPath}/admin/deploy/authentication',
		$("#migrateForm").serialize(),
        function(data){
            if(data.status == 200){
            	complete("migrateAuth");
        		setTimeout('getSourceStoreFile()', 500);
		    } else {
		    	toastr.error("互信失败！"+data.message);  
		    	migrateGoOn("authentication");
		    	warn("migrateAuth");
		    }
       }, 'json');
}
/**
 * 数据迁移第四步：获取源数据文件
 */
function getSourceStoreFile(){
	active("migrateData");
	$.post('${request.contextPath}/admin/deploy/store/file',
		$("#migrateForm").serialize(),
        function(data){
			$("#migrateTable tbody").html(data);
       	}).fail(function(response) {
    	   $("#migrateTable tbody").html("网络错误，请查看后台日志");
    	   migrateGoOn("getSourceStoreFile");
   		   warn("migrateData");
       	});
}
/**
 * 数据迁移第五步：真正文件迁移
 */
function migrateStroreFile(){
	$("#sourceIp").attr("disabled", "disabled");
	$("#sourceHome").attr("disabled", "disabled");
	$("#destIp").attr("disabled", "disabled");
	$("#destHome").attr("disabled", "disabled");
	active("migrateScp");
	$("#migrateProgressDiv").addClass("active");
	var trs = $("#migrateTable tr[status='0']");
	if(trs.length != 0) {
		scpStroreFile(trs.eq(0));
	} else {
		active("migrateFinish");
		$("#migrateProcessBar").width("100%");
		$("#migrateProgressDiv").removeClass("active");
		setTimeout('alert("迁移完成")', 1000);
	}
}

function scpStroreFile(tr){
	var pid = tr.attr("data-tt-parent-id");
	var slashIndex = pid.indexOf("_");
	// 展开二级foler
	if(slashIndex != -1){
		$("#migrateTable").treetable("expandNode", pid.substring(0, slashIndex));
	}
	// 展开父folder
	$("#migrateTable").treetable("expandNode", pid);
	var jsonData = {};
	jsonData.sourceIp = $("#sourceIp").val();
	jsonData.sourceHome = $("#sourceHome").val();
	jsonData.destIp = $("#destIp").val();
	jsonData.destHome = $("#destHome").val();
	jsonData.storeFile = tr.data("json");
    // 大于5M显示load标识
    if(jsonData.storeFile.size > 5242880){
    	tr.find("span.loading").addClass("mqloading");
    }
    // 有滚动条
    if($("#migrateTable").height() > 400){
	    var trOffset = tr.offset().top - $("#migrateDiv").offset().top;
	    // 超过一半，滚动
	    if(trOffset > 200){
	    	//$("#migrateDiv").scrollTop($("#migrateDiv").scrollTop() + trOffset - 200);
	    	$("#migrateDiv").stop(true, true).animate({scrollTop: $("#migrateDiv").scrollTop() + trOffset - 200}, 200);
	    }
    }
	$.ajax({
	    type: 'POST',
	    url: '${request.contextPath}/admin/deploy/scp/storefile',
	    data: JSON.stringify(jsonData),
	    success: function(data) { 
	    	var transferComponent = tr.find(".transComp");
	    	tr.find("span.loading").removeClass("glyphicon-tag").removeClass("mqloading");
            if(data.status == 200){
            	tr.attr('status', '2');
            	transferComponent.removeClass("glyphicon-remove").addClass("glyphicon-ok").attr("title", "传输成功");
            	var md5Compo = tr.find(".md5Comp");
            	if(data.result.md5OK){
            		md5Compo.addClass("glyphicon-ok");
            	} else {
            		md5Compo.addClass("glyphicon-remove");
            		if(data.result.sourceMD5){
            			md5Compo.attr("title", data.result.sourceMD5 + "!=" + data.result.destMD5);
            		}
            		var sizeCompo = tr.find(".sizeComp");
            		if(data.result.sizeOK){
            			sizeCompo.addClass("glyphicon-ok").attr("title", "大小相同");
            		} else {
            			sizeCompo.addClass("glyphicon-remove");
            			if(data.result.sourceSize){
            				sizeCompo.attr("title", data.result.sourceSize + "!=" + data.result.destSize);
            			}
            		}
            	}
            	// 合并传输的单独处理
            	if(tr.attr("date-type") == 'folder' && data.result.scpVOMap){
            		$("#migrateTable tr[data-tt-parent-id='"+tr.attr("data-tt-id")+"']").each(function(){
            			var file = $(this).find(".dataFile").eq(0).html();
            			var rst = data.result.scpVOMap[file]
            			if(rst){
            				var md5Compo2 = $(this).find(".md5Comp");
            				if(rst.md5OK){
            					md5Compo2.addClass("glyphicon-ok");
                        	} else {
                        		md5Compo2.addClass("glyphicon-remove").attr("title", rst.sourceMD5 + "!=" + rst.destMD5);
                        		var sizeCompo2 = $(this).find(".sizeComp");
                        		if(rst.sizeOK){
                        			sizeCompo2.addClass("glyphicon-ok").attr("title", "大小相同");
                        		} else {
                        			sizeCompo2.addClass("glyphicon-remove").attr("title", rst.sourceSize + "!=" + rst.destSize);
                        		}
                        	}
            			} else {
            				console.error("="+file+"="+data.result.scpVOMap);
            			} 
            		});
            		// 展开folder
            		if(!data.result.md5OK){
	   		    		$("#migrateTable").treetable("expandNode", tr.attr("data-tt-id"));
            		}
            	}
            	scpBytes += data.result.size;
            	var percent = (scpBytes / totalBytes) * 100;
            	$("#migrateProcessBar").width(formatNum(percent) + "%");
				$("#migrateSpeed").html(data.result.humanReadableRate);
				$("#migrated").html(formatSize(scpBytes));
				migrateStroreFile();
		    } else {
		    	toastr.error("传输失败！"+data.message);
		    	migrateGoOn("migrateStroreFile");
		    	warn("migrateScp");
		    	$("#migrateProgressDiv").removeClass("active");
		    	transferComponent.addClass("glyphicon-remove").attr("title", data.message);
		    	tr.find("span.loading").addClass("glyphicon-tag pointer").attr("title", "标记为已处理?");
		    	// 展开folder
		    	if(tr.hasClass("branch")){
		    		$("#migrateTable").treetable("expandNode", tr.attr("data-tt-id"));
		    	}
		    }
	    },
	    contentType: "application/json",
	    dataType: 'json'
	});
}

function skip(id){
	if($("#" + id).attr("status") == "0"){
		$("#" + id).find(".transComp").removeClass("glyphicon-remove").addClass("glyphicon-ok");
		$("#" + id).attr("status", "2");
		alert($("#" + id).find(".dataFile").eq(0).html()+"标记为已处理");
	}
}
</script>
</#if>